﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admincp_phanlopgv : AdminPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        this.FillDataToDropDownList();
        this.FillDataToListView();
    }

    private void FillDataToDropDownList()
    {
        ddlGiaoVien.DataSource = db.GiaoViens.Where(gv=>gv.TrangThai == true);
        ddlGiaoVien.DataTextField = "TenGiaoVien";
        ddlGiaoVien.DataValueField = "MaGiaoVien";
        ddlGiaoVien.DataBind();

        ddlLopHoc.DataSource = db.LopHocs.Where(lh=>lh.TrangThai == true);
        ddlLopHoc.DataTextField = "TenLop";
        ddlLopHoc.DataValueField = "MaLop";
        ddlLopHoc.DataBind();

        ddlMonHoc.DataSource = db.MonHocs.Where(mh=>mh.TrangThai == true);
        ddlMonHoc.DataTextField = "TenMonHoc";
        ddlMonHoc.DataValueField = "MaMonHoc";
        ddlMonHoc.DataBind();
    }

    protected void ThemPhanLopDayGiaoVien(object sender, EventArgs e)
    {
        try
        {
            PhanLopGiaoVien plgv = new PhanLopGiaoVien();
            plgv.MaGiaoVien = ddlGiaoVien.SelectedValue;
            plgv.MaLop = ddlLopHoc.SelectedValue;
            plgv.MaMonHoc = ddlMonHoc.SelectedValue;
            db.PhanLopGiaoViens.InsertOnSubmit(plgv);
            db.SubmitChanges();
            this.FillDataToListView();
        }
        catch
        {
        }
    }

    private void FillDataToListView()
    {
        var plgv = from pl in db.PhanLopGiaoViens
                   select new
                   {
                       MaGiaoVien = pl.MaGiaoVien,
                       TenGiaoVien = pl.GiaoVien.TenGiaoVien,
                       MaLop = pl.MaLop,
                       TenLop = pl.LopHoc.TenLop,
                       MaMonHoc = pl.MaMonHoc,
                       TenMonHoc = pl.MonHoc.TenMonHoc
                   };
        lvPhanLopDayChoGiaoVien.DataSource = plgv;
        lvPhanLopDayChoGiaoVien.DataBind();
    }
}